package xyz.icxl.android.architecture.dialog

import android.view.View
import android.widget.TextView
import androidx.fragment.app.FragmentManager
import xyz.icxl.android.architecture.R
import xyz.icxl.android.architecture.ui.BaseDialogFragment
import xyz.icxl.kotlion.ext.view.selfClickListener

/**
 * 文件描述：带 是、否两个按钮弹窗
 *
 * 文件创建人：cxl
 *
 * 创建时间：2021 年 12月 01 日
 *
 * 文件版本：v1.0
 *
 * 版本描述：创建文件
 */
class ConfirmDialog(
    private val message: CharSequence,
    private val leftText: CharSequence? = null,
    private val rightText: CharSequence? = null,
    private val clickListener: OnClickButtonListener? = null
) : BaseDialogFragment() {


    companion object {
        fun show(
            manager: FragmentManager,
            message: CharSequence,
            onClickListener: OnClickButtonListener? = null
        ) {
            ConfirmDialog(message, clickListener = onClickListener).show(manager)
        }
    }


    override fun layoutId(): Int = R.layout.dialog_confirm
    override fun doSomething(rootView: View) {
        rootView.findViewById<TextView>(R.id.dialog_content_tv).text = message
        if (leftText != null) {
            rootView.findViewById<TextView>(R.id.dialog_no_tv).text = leftText
        }
        if (rightText != null) {
            rootView.findViewById<TextView>(R.id.dialog_yes_tv).text = rightText
        }

        rootView.findViewById<View>(R.id.dialog_yes_tv).selfClickListener {
            dismiss()
            clickListener?.onClickRight()
        }
        rootView.findViewById<View>(R.id.dialog_no_tv).setOnClickListener {
            dismiss()
            clickListener?.onClickLeft()
        }
    }

    fun show(
        manager: FragmentManager
    ) {
        super.show(manager, "ProConfirmDialog")
    }

    interface OnClickButtonListener {
        fun onClickRight()

        fun onClickLeft(){}
    }
}